<?php
/*******************************************************************************
 *
 *  Name: David Jarman
 *
 *  Date: 5/3/2012
 *  
 *  Description: Shows the Incident data that has been set and allows the 
 *               user to edit the estimate time, status, and other related
 *               info
 *  
 *  Author: David Jarman
 *  
 *  Todo:
 *     NONE
 *
 *  Modification History:  
 * 
 *   Date         Name
 *  ----------   --------------
 *  2012-04-25   DAVID JARMAN
 *  2012-04-25   DAVID JARMAN
 *  2012-04-25   DAVID JARMAN
 *  2012-04-24   DAVID JARMAN
 * 
 *****************************************************************************/
?>
<html>
	<head>
	</head>

	<body>
        <div style="text-align:center">
            <h4><?php echo $IncidentData['IncidentID'] . ' - ' . $IncidentData['Name']?></h4>
        </div>
        <form name="IncidentInfo" action="" method="post">
	        <table border="0.0" style="width:100%;">
	        <tr>
		        <td style="text-align:left">
			        <label id="Estimate_Time_Label">Estimate Time Till Completion: </label>
		        </td>
		        <td style="text-align:right">
		            <input name="EstimateDateInput" type="text" value="<?php
                            $database_estimate = $IncidentData['ExpectedCompletionDate']; 
                            if( $database_estimate == '') 
                                echo 'MM/DD/YYYY';
                            else
                            {
                                $prettyFormat = '%m-%d-%Y';
                                $toPrint = mdate($prettyFormat, strtotime($database_estimate));
                                echo $toPrint;
                            }
                        ?>" size="14" />
                    <input name="EstimateTimeInput" type="text" value="<?php
                            $database_estimate = $IncidentData['ExpectedCompletionDate'];
                            if( $database_estimate == '' )
                                echo 'hh:mm AM/PM';
                            else
                            {
                                $prettyFormat = '%h:%i %a';
                                $toPrint = mdate($prettyFormat, strtotime($database_estimate));
                                echo $toPrint;
                            }
                        ?>" size="11" />
		        </td>
	        </tr>
	        <tr>
		        <td style="text-align:left">
			        <label id="Status_Label">Status: </label>
		        </td>
		        <td style="text-align:right">
			        <select name="Status_Select">
				        <?php
					        $Status_Options = array(
                                "Pending",
						        "Under Repair",
						        "Resolved"
					        );

                            //remove certain options depending on the status
                            if($IncidentData['Status'] == 2)
                            {
                                $Status_Options = array_reverse( $Status_Options );
                                array_pop($Status_Options);
                                $Status_Options = array_reverse( $Status_Options );
                            }
                            elseif($IncidentData['Status'] == 3)
                            {
                                $Status_Options = array("Resolved");
                            }
					        
                            //display each status as an option
					        foreach( $Status_Options as $status )
					        {
						        echo "<option>$status</option>";
					        }
				        ?>
			        </select>
		        </td>
	        </tr>
	        <tr>
		        <td style="text-align:left">
			        <label id="Time_Begun_Label">Work Started: </label>
		        </td>
		        <td style="text-align:right">
                   <input name="WorkStartedDate" type="text" value="<?php
                            $database_started = $IncidentData['WorkStarted']; 
                            if( $database_started == '') 
                                echo 'MM/DD/YYYY';
                            else
                            {
                                $prettyFormat = '%m-%d-%Y';
                                $toPrint = mdate($prettyFormat, strtotime($database_started));
                                echo $toPrint;
                            }
                        ?>" size="14" />
                    <input name="WorkStartedTime" type="text" value="<?php
                            $database_started = $IncidentData['WorkStarted'];
                            if( $database_started == '' )
                                echo 'hh:mm AM/PM';
                            else
                            {
                                $prettyFormat = '%h:%i %a';
                                $toPrint = mdate($prettyFormat, strtotime($database_started));
                                echo $toPrint;
                            }
                        ?>" size="11" />
		        </td>
	        </tr>
	        <tr>
		        <td>
			        <label id="Time_Finished_Label">Work Finished: </label>
		        </td>
		        <td style="text-align:right">
			        <input name="WorkFinishedDate" type="text" value="<?php
                            $database_finished = $IncidentData['WorkFinished']; 
                            if( $database_finished == '' ) 
                                echo 'MM/DD/YYYY';
                            else
                            {
                                $prettyFormat = '%m-%d-%Y';
                                $toPrint = mdate($prettyFormat, strtotime($database_finished));
                                echo $toPrint;
                            }
                        ?>" size="14" />
                    <input name="WorkFinishedTime" type="text" value="<?php
                            $database_finished = $IncidentData['WorkFinished'];
                            if( $database_finished == '' )
                                echo 'hh:mm AM/PM';
                            else
                            {
                                $prettyFormat = '%h:%i %a';
                                $toPrint = mdate($prettyFormat, strtotime($database_finished));
                                echo $toPrint;
                            }
                                
                        ?>" size="11" />
		        </td>
	        </tr>
        </table>

        <!--- Section for the repair person to fill in additional info about the incident --->
        <div>
	        <table border="0.0" style="width:100%;">
		        <tr>
			        <td style="text-align:left">
				        <label id="Incident_Cause_Label">Cause of Incident: </label>
			        </td>
			        <td style="text-align:right">
				        <select name="Cause">
					        <?php
						        $Incident_Cause_Types = array(
							        "Unknown",
							        "Weather",
							        "Vandalism",
							        "Corrosion",
							        "Accident",
							        "Other"
						        );
						        $i = 1;
						        foreach( $Incident_Cause_Types as $Cause )
						        {
                                    if($i == $IncidentData['CauseCode'])
                                    {
                                        echo "<option selected=\"selected\">" . $Incident_Cause_Types[$i-1] . "</option>";
                                    }
                                    else
                                    {
							            echo "<option>$Cause</option>";
                                    }
                                    $i = $i + 1;
						        }
					        ?>
				        </select>
			        </td>
		        </tr>
		        <tr>
			        <td>
				        <label id="IncidentDescriptionLabel">Describe Incident: </label>
			        </td>
			        <td style="text-align:right">
				        <textarea name="IncidentDescription" rows="5" cols="55"><?php
                        echo $IncidentData['IRTeamDescription'];
                        ?></textarea>
			        </td>
		        </tr>
	        </table>
        </div>
        <div>
            <?php
                //link to the relatedreports page
                echo anchor("repaircrew/relatedreports/".$IncidentData['IncidentID'],"View Reports");
            ?>
        </div>
        <br>
        <div style="text-align:center">
	        <input name="SubmitForm" type="submit" value="Submit" />
        </div>
    </form>
            <?php 
                //Print any erros that occured
                echo validation_errors(); 
            ?>
	</body>
</html>
